package com.zdlyh.controller;

import com.zdlyh.annotation.SystemLog;
import com.zdlyh.domain.ResponseResult;
import com.zdlyh.domain.dto.ArticleDto;
import com.zdlyh.service.ArticleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/article")
@Api(tags = "文章",description = "文章相关接口")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    /*@GetMapping("/list")
    public List<Article> test(){
        return articleService.list();
    }*/

    @SystemLog(businessName = "查询热门文章")
    @GetMapping("/hotArticleList")
    @ApiOperation(value = "查询热门文章",notes = "查询浏览量为前十的热门文章")
    public ResponseResult hotArticleList(){
        return articleService.hotArticleList();
    }

    @GetMapping("/newArticleList")
    @ApiOperation(value = "查询最新文章",notes = "创建时间为前五")
    public ResponseResult newArticleList(){
        return articleService.newArticleList();
    }

    @GetMapping("/websiteInfo")
    @ApiOperation(value = "查询网站咨询信息",notes = "网站咨询信息")
    public ResponseResult websiteInfo(){
        return articleService.websiteInfo();
    }

    @GetMapping("/articleList")
    @ApiOperation(value = "查询文章列表分页",notes = "可根据分类id查,文章标题查询并分页")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "categoryId",value = "分类id",dataType = "Long"),
            @ApiImplicitParam(name = "title",value = "文章标题",dataType = "String")
    })
    public ResponseResult getArticleList(Long categoryId,String title){
        return articleService.getArticleList(categoryId,title);
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "获取文章详情",notes = "根据文章id查询文章详情")
    public ResponseResult getArticleById(@PathVariable("id") Long id){
        return articleService.getArticleDetails(id);
    }

    @PutMapping("/updateViewCount/{id}")
    @ApiOperation(value = "更新文章访问量",notes = "根据文章id更新文章访问量")
    public ResponseResult updateViewCount(@PathVariable("id") Long id){
        return articleService.updateViewCount(id);
    }
}
